package it.gma.torero.parsing.token;

import it.gma.torero.parsing.Tokenizer;
import it.gma.torero.parsing.Tokenizer.MalformedException;

public class TokenFactory {

	// , , , , , , , ,

	public static Operator newOperator(String sequence) throws MalformedException {
		if ("!".equals(sequence)) {
			return new Not(sequence);
		} else if ("&&".equals(sequence)) {
			return new And(sequence);
		} else if ("||".equals(sequence)) {
			return new Or(sequence);
		} else if ("!=".equals(sequence)) {
			return new NotEquals(sequence);
		} else if (">".equals(sequence)) {
			return new Greater(sequence);
		} else if ("<".equals(sequence)) {
			return new Lesser(sequence);
		} else if (">=".equals(sequence)) {
			return new GreaterEqual(sequence);
		} else if ("<=".equals(sequence)) {
			return new LesserEqual(sequence);
		} else if ("==".equals(sequence)) {
			return new Equal(sequence);
		} else if ("%".equals(sequence)) {
			return new Xor(sequence);
		}else if ("=>".equals(sequence)) {
			return new Implies(sequence);
		} else {
			throw new Tokenizer.MalformedException("Operator " + sequence + " doesn't exist");
		}
	}

	public static Constant newConstant(String sequence) {
		if ("'true'".equals(sequence) || "'false'".equals(sequence)) {
			return new BooleanConstant(sequence);
			
		} else if ("'null'".equals(sequence)) {	
			return new ValueConstant(sequence);
		} else {
			return new ValueConstant(sequence);
		}
	}

	public static Group newGroup(String sequence) throws MalformedException {
		return new Group(sequence);
	}

	public static Variable newVariable(String sequence) {
		return new Variable(sequence);
	}

}
